﻿using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using Localization;
using SinBiota.Model.Business.PersistenceServices.Interfaces;
using SinBiota.Model.Entities;
using SinBiota.Model.Entities.CustomAttributes;
using StructureMap;

namespace Sinbiota.Web.Models
{

    #region models

    public class TaxonDetailsModel
    {
        public Taxon Taxon  { get; set; }
        public int MaxDepth { get; set; }
        public virtual IList<Taxon> Ancestors { get; private set; }
        public virtual IList<Taxon> Children { get; private set; }
        public bool CanAddChildren { get; set; }

        public TaxonDetailsModel(Taxon taxon, int maxDepth, IList<Taxon> ancestors = null, bool canAddChildren = false)
        {
            Taxon = taxon;
            MaxDepth = maxDepth;
            Ancestors = ancestors ?? new List<Taxon>();
            var taxonPersistenceServices = ObjectFactory.GetInstance(typeof(ITaxonPersistenceServices)) as ITaxonPersistenceServices;
            Children = taxonPersistenceServices != null ? taxonPersistenceServices.FindChildren(taxon) : new List<Taxon>();
            CanAddChildren = canAddChildren;
        }
    }

    public class TaxonCreateModel
    {
        public TaxonCreateModel()
        {
            RankList = new []{COLRank.SubOrder, COLRank.SuperFamily, COLRank.Family, COLRank.Genus, COLRank.Species};
        }

        public Taxon Parent { get; set; }
        public string[] RankList { get; set; }

        [LocalizedName("Name", NameResourceType = typeof(Strings))]
        [DataType(DataType.Text)]
        [Required(ErrorMessageResourceType = typeof(Messages), ErrorMessageResourceName = "FieldCannotBeEmpty")]
        public string TaxonName { get; set; }

        [LocalizedName("Rank", NameResourceType = typeof(Strings))]
        [DataType(DataType.Text)]
        [Required(ErrorMessageResourceType = typeof(Messages), ErrorMessageResourceName = "FieldCannotBeEmpty")]
        public string TaxonRank { get; set; }

        [LocalizedName("Reference", NameResourceType = typeof(Strings))]
        [DataType(DataType.Text)]
        [Required(ErrorMessageResourceType = typeof(Messages), ErrorMessageResourceName = "FieldCannotBeEmpty")]
        public string TaxonReference { get; set; }

    }
    #endregion

}